﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace PersonaLibrary.Converters
{
    internal class ManySourceInOneConverter : IMultiValueConverter
    {
        public object Convert(object[] values, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            List<object> result = new List<object>();
            foreach (object o in values)
            {
                if(o is IEnumerable)
                    result.AddRange(((IEnumerable)o).Cast<object>());
                else
                    result.Add(o);
            }
            return result;
        }

        public object[] ConvertBack(object value, System.Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            return new object[1]{ value };
        }
    }
}
